<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Storage;

/**
 * App\AppConfig
 *
 * @mixin \Eloquent
 */
class AppConfig extends Model
{
    public $timestamps = false;
    protected $table = "app_config";

    /**
     * 修改配置
     * @param $config
     * @param $request
     * @return array
     */
    static function ConfigModify($config, $request)
    {
        $config->ks_more_title = $request->ks_more_title;
        $config->share_invite_title = $request->share_invite_title;
        $config->share_posting_title = $request->share_posting_title;
        $config->share_game_title = $request->share_game_title;
        if ($request->has('ks_more_pic')) {
            $config->ks_more_pic = Storage::url($request->ks_more_pic->store('/', 'oss'));
        }

        if ($request->has('ht_more_pic')) {
            $config->ht_more_pic = Storage::url($request->ht_more_pic->store('/', 'oss'));
        }
        if ($request->has('share_invite_pic')) {
            $config->share_invite_pic = Storage::url($request->share_invite_pic->store('/', 'oss'));
        }
        if ($request->has('share_posting_pic')) {
            $config->share_posting_pic = Storage::url($request->share_posting_pic->store('/', 'oss'));
        }
        if ($request->has('share_game_pic')) {
            $config->share_game_pic = Storage::url($request->share_game_pic->store('/', 'oss'));
        }

        if (!$config->save()) {
            return ['status' => 2, 'message' => '修改失败'];
        }
        return ['status' => 1, 'message' => '修改成功'];
    }
}
